/*----------------------------------------------------------------------
  - File name      : STC8Hx_SYSCLK.h
  - Author         : Quark Team
  - Update date    : 2020-12-13                
  -	Copyright      : Gevico Electronic studio   
  - Module comments: Header file of system clock module. 
-----------------------------------------------------------------------*/
#ifndef __STC8Ax_SYSCLK_H_
#define __STC8Ax_SYSCLK_H_
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "STC8Ax_STARTUP.h"
/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: System clock ferquency division define   |
--------------------------------------------------------*/

#define     SYSCLK_DIV1     0x10
#define     SYSCLK_DIV2     0x20
#define     SYSCLK_DIV4     0x40
#define     SYSCLK_DIV8     0x70
#define    SYSCLK_DIV16     0x90
#define    SYSCLK_DIV32     0xB0
#define    SYSCLK_DIV64     0xD0
#define   SYSCLK_DIV128     0xF0

/*--------------------------------------------------------
| @Description: Master clock source enum type            |
--------------------------------------------------------*/

typedef enum
{
	AUTO = 0x00, /* stc -isp toll control */
	HIRC = 0x01, /* High internal 4MHz~24MHz oscillator */
	LIRC = 0x02, /* Internal 32KHz oscillator           */
  XOSC = 0x03  /* External oscillator control         */
} MCLKSrc_Type;

/*--------------------------------------------------------
| @Description:IRC frequency little trimmer enum type    |
--------------------------------------------------------*/

typedef enum
{
	TRIM0 = 0x00, /* stc -isp toll control */
	TRIM1 = 0x01, /* High internal 4MHz~24MHz oscillator */
	TRIM2 = 0x02, /* Internal 32KHz oscillator           */
  TRIM3 = 0x03  /* External oscillator control         */
} LIRCTRIM_Type;

/*--------------------------------------------------------
| @Description: System clock out pin enum type           |
--------------------------------------------------------*/

typedef enum
{
	SCLK_OUT_P54 = 0x00, /* GPIO Port 5 pin 4 */
	SCLK_OUT_P16 = 0x01  /* GPIO Port 1 pin 6 */
} SCLKOut_Type;

/*--------------------------------------------------------
| @Description: System clock init struct type            |
--------------------------------------------------------*/

typedef struct
{
	MCLKSrc_Type MCLKSrc;  /* Master clock source */
	
	uint8 IRCTRIM;    /* IRC frequency trimmer */
	
	LIRCTRIM_Type LIRCTRIM;  /* IRC little trimmer */
	
	uint8 MCLKDiv;  /* Master clock frequency division 
	                Parameter range: 0 <= MDiv <= 255 */
	uint8 SCLKDiv;  /* System clock ferquency division: 
                    ----------------------------------
                    |     value    |     division    |
                    ----------------------------------
                    |     0x00     |    not output   |
                    ----------------------------------
                    |     0x10     |    SYSCLK / 1   |
                    ----------------------------------
                    |     0x20     |    SYSCLK / 2   |
                    ----------------------------------
                    |     0x40     |    SYSCLK / 4   |
                    ----------------------------------
                    |     0x70     |    SYSCLK / 8   |
                    ----------------------------------
                    |     0x90     |   SYSCLK / 16   |
                    ----------------------------------	
                    |     0xB0     |   SYSCLK / 32   |
                    ----------------------------------	
                    |     0xD0     |   SYSCLK / 64   |
                    ----------------------------------	
                    |     0xF0     |  SYSCLK / 128   |
                    --------------------------------*/
  SCLKOut_Type SCLKOutPin; /* Select system clock output pin */
  
} SYSCLK_InitType;

/*-----------------------------------------------------------------------
|                             API FUNCTION                              |
-----------------------------------------------------------------------*/

uint32 GET_SYSCLIK_FRE(void);
FSCSTATE SYSCLK_Init(const SYSCLK_InitType *SYSCLKn);

#endif
/*-----------------------------------------------------------------------
|          END OF FLIE        (C) COPYRIGHT Gevico Electronics          | 
-----------------------------------------------------------------------*/

